﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DDD.Core;

namespace DDDTest.Core {
    [TestClass]
    public class Image2D_GetSet {

        /// <summary>
        /// Get/Setのテスト(RGB8)
        /// </summary>
        [TestMethod]
        public void Test_GetSet_RGB8 () {
            var width = 64;
            var height = 64;
            var cpp = 3;
            var img = new Image2D<float> (PixelFormat.RGB8, width, height);

            var expected = new float[width * height * cpp];
            for (var i = 0; i < expected.Length; i++) {
                expected[i] = i;
            }
            img.Set (0, 0, width, height, expected);

            var actual = new float[width * height * cpp];
            img.Get (0, 0, width, height, actual);

            CollectionAssert.AreEqual (expected, actual);
        }

        /// <summary>
        /// Get/Setのテスト(RGB16i)
        /// </summary>
        [TestMethod]
        public void Test_GetSet_RGB16i () {
            var width = 64;
            var height = 64;
            var cpp = 3;
            var img = new Image2D<short> (PixelFormat.RGB16i, width, height);

            var expected = new short[width * height * cpp];
            for (var i = 0; i < expected.Length; i++) {
                expected[i] = (short)i;
            }
            img.Set (0, 0, width, height, expected);

            var actual = new short[width * height * cpp];
            img.Get (0, 0, width, height, actual);

            CollectionAssert.AreEqual (expected, actual);
        }

        /// <summary>
        /// Get/Setのテスト(RGB32f)
        /// </summary>
        [TestMethod]
        public void Test_GetSet_RGB32f () {
            var width = 64;
            var height = 64;
            var cpp = 3;
            var img = new Image2D<float> (PixelFormat.RGB32f, width, height);

            var expected = new float[width * height * cpp];
            for (var i = 0; i < expected.Length; i++) {
                expected[i] = i;
            }
            img.Set (0, 0, width, height, expected);

            var actual = new float[width * height * cpp];
            img.Get (0, 0, width, height, actual);

            CollectionAssert.AreEqual (expected, actual);
        }

        /// <summary>
        /// Set/Getのテスト(RGBA32i)、一部だけ
        /// </summary>
        [TestMethod]
        public void Test_GetSet_RGBA32i () {
            var width = 64;
            var height = 64;
            var cpp = 4;
            var img = new Image2D<int> (PixelFormat.RGBA32i, width, height);

            var expected = new int[16 * 16 * cpp];
            for (var i = 0; i < expected.Length; i++) {
                expected[i] = i;
            }
            img.Set (32, 32, 16, 16, expected);

            var pixels = new int[16 * 16 * cpp];
            img.Get (32, 32, 16, 16, pixels);

            CollectionAssert.AreEqual (expected, pixels);
        }

    }
}
